
package gui;

import business.Veiculo;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import vo.VeiculoVO;

public class Veiculo_Pesquisar extends javax.swing.JFrame {
   
    public Veiculo_Pesquisar() {
        initComponents();
        updateVeiculos();
    }

  
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButtonVeiculoPesquisarSelecionar = new javax.swing.JButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButtonVeiculoPesquisarAno = new javax.swing.JRadioButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableCarroPrincipalTabela = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("gui/Bundle"); // NOI18N
        jButtonVeiculoPesquisarSelecionar.setText(bundle.getString("Veiculo_Pesquisar.jButtonVeiculoPesquisarSelecionar.text")); // NOI18N
        jButtonVeiculoPesquisarSelecionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVeiculoPesquisarSelecionarActionPerformed(evt);
            }
        });

        jRadioButton4.setText(bundle.getString("Veiculo_Pesquisar.jRadioButton4.text")); // NOI18N

        jRadioButton3.setText(bundle.getString("Veiculo_Pesquisar.jRadioButton3.text")); // NOI18N
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });

        jRadioButton2.setText(bundle.getString("Veiculo_Pesquisar.jRadioButton2.text")); // NOI18N

        jRadioButtonVeiculoPesquisarAno.setText(bundle.getString("Veiculo_Pesquisar.jRadioButtonVeiculoPesquisarAno.text")); // NOI18N

        jLabel2.setText(bundle.getString("Veiculo_Pesquisar.jLabel2.text")); // NOI18N

        jTableCarroPrincipalTabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Placa", "Marca", "Modelo", "Ano", "Quilometragem", "Categoria", "Status", "Foto"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTableCarroPrincipalTabela);
        jTableCarroPrincipalTabela.getColumnModel().getColumn(0).setHeaderValue(bundle.getString("Veiculo_Pesquisar.jTableCarroPrincipalTabela.columnModel.title0")); // NOI18N
        jTableCarroPrincipalTabela.getColumnModel().getColumn(1).setHeaderValue(bundle.getString("Veiculo_Pesquisar.jTableCarroPrincipalTabela.columnModel.title1")); // NOI18N
        jTableCarroPrincipalTabela.getColumnModel().getColumn(2).setHeaderValue(bundle.getString("Veiculo_Pesquisar.jTableCarroPrincipalTabela.columnModel.title2")); // NOI18N
        jTableCarroPrincipalTabela.getColumnModel().getColumn(3).setHeaderValue(bundle.getString("Veiculo_Pesquisar.jTableCarroPrincipalTabela.columnModel.title3")); // NOI18N
        jTableCarroPrincipalTabela.getColumnModel().getColumn(4).setHeaderValue(bundle.getString("Veiculo_Pesquisar.jTableCarroPrincipalTabela.columnModel.title4")); // NOI18N
        jTableCarroPrincipalTabela.getColumnModel().getColumn(5).setHeaderValue(bundle.getString("Veiculo_Pesquisar.jTableCarroPrincipalTabela.columnModel.title5")); // NOI18N
        jTableCarroPrincipalTabela.getColumnModel().getColumn(6).setHeaderValue(bundle.getString("Veiculo_Pesquisar.jTableCarroPrincipalTabela.columnModel.title6")); // NOI18N
        jTableCarroPrincipalTabela.getColumnModel().getColumn(7).setHeaderValue(bundle.getString("Veiculo_Pesquisar.jTableCarroPrincipalTabela.columnModel.title7")); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel1.setText(bundle.getString("Veiculo_Pesquisar.jLabel1.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 373, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jRadioButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButtonVeiculoPesquisarAno)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButton4))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonVeiculoPesquisarSelecionar, javax.swing.GroupLayout.DEFAULT_SIZE, 645, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 645, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(257, 257, 257)
                        .addComponent(jLabel1)
                        .addGap(0, 256, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jRadioButtonVeiculoPesquisarAno)
                        .addComponent(jRadioButton4)
                        .addComponent(jRadioButton2)
                        .addComponent(jRadioButton3))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButtonVeiculoPesquisarSelecionar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonVeiculoPesquisarSelecionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVeiculoPesquisarSelecionarActionPerformed

        String modelo = (String) jTableCarroPrincipalTabela.getValueAt(jTableCarroPrincipalTabela.getSelectedRow(),0);
        String marca = (String) jTableCarroPrincipalTabela.getValueAt(jTableCarroPrincipalTabela.getSelectedRow(),1);
        String ano = (String) jTableCarroPrincipalTabela.getValueAt(jTableCarroPrincipalTabela.getSelectedRow(),2);
        String categoria = (String) jTableCarroPrincipalTabela.getValueAt(jTableCarroPrincipalTabela.getSelectedRow(),3);
        String placa = (String) jTableCarroPrincipalTabela.getValueAt(jTableCarroPrincipalTabela.getSelectedRow(),4);
        String chassi = (String) jTableCarroPrincipalTabela.getValueAt(jTableCarroPrincipalTabela.getSelectedRow(),5);
        String foto = (String) jTableCarroPrincipalTabela.getValueAt(jTableCarroPrincipalTabela.getSelectedRow(),6);
        int kilometragem = (int) jTableCarroPrincipalTabela.getValueAt(jTableCarroPrincipalTabela.getSelectedRow(),7);

        Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalPlaca(placa);
        //System.out.println(Veiculo_Principal.getInstance().getjTextFieldVeiculoPrincipalPlaca());
        
       Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalMarca(marca);
       Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalModelo(modelo);
       Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalAno(ano);
       Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalKilometragem(Integer.toString(kilometragem));
       //Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalChassis(chassi);
       Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalFoto(foto);
       Veiculo_Principal.getInstance().setjComboBoxVeiculoPrincipalCategoria(categoria);
        
       Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalPlacaEnabled(false);
       Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalMarcaEnabled(false);
       Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalModeloEnabled(false);
      // Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalChassisEnabled(false);
       Veiculo_Principal.getInstance().setjTextFieldVeiculoPrincipalAnoEnabled(false);
       Veiculo_Principal.getInstance().setjComboBoxVeiculoPrincipalCategoriaEnabled(false);
       
       
        Veiculo_Principal.getInstance().setsStatus(Veiculo_Principal.StatusVeiculoPrincipal.scPesquisado); 
        dispose();
    
    }//GEN-LAST:event_jButtonVeiculoPesquisarSelecionarActionPerformed

    private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton3ActionPerformed
              
   
     private void updateVeiculos() {
         
        List<VeiculoVO> lista = Veiculo.getVeiculos();

        Object[][] dados = new Object[lista.size()][8];


        for (int i = 0; i < lista.size(); i++) {
            VeiculoVO veiculo= (VeiculoVO) lista.get(i);
            dados[i][0] = veiculo.getModelo();
            dados[i][1] = veiculo.getMarca();
            dados[i][2] = veiculo.getAno();
            dados[i][3] = veiculo.getCategoria();
            dados[i][4] = veiculo.getPlaca();
            dados[i][5] = veiculo.getStatus();
            dados[i][6] = veiculo.getFotoPath();
            dados[i][7] = veiculo.getKilometragem();
            

                    
       
            ((DefaultTableModel)jTableCarroPrincipalTabela.getModel()).addRow(dados[i]);
        }

        
    }
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonVeiculoPesquisarSelecionar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JRadioButton jRadioButtonVeiculoPesquisarAno;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableCarroPrincipalTabela;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
